package com.community.controller;

import com.community.entity.Major;
import com.community.service.MajorService;
import com.community.util.Result;
import com.community.util.Search;
import com.feng.fengDUtil.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping(value = "/major")
public class MajorAction {

    @Autowired
    private MajorService majorService;


    @RequestMapping(value = "/list")
    public Result list(Page page, Search search) {
        majorService.query(page,search);
        return Result.success(page);
    }

    @RequestMapping(value = "/del")
    public Result del(String ids) {
        majorService.deleteByIds(Major.class,ids);
        return Result.success();
    }

    @RequestMapping(value = "/uploadMajor", method = RequestMethod.POST)
    public Result uploadMajor(MultipartFile file, Search search){
        try {
            return Result.success(majorService.uploadMajor(file,search));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    @RequestMapping(value = "/uploadMajorResult", method = RequestMethod.POST)
    public Result uploadMajorResult(MultipartFile file, Search search){
        try {
            return Result.success(majorService.uploadMajorResult(file,search));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

}
